function K = completeRotationMatrix(known_axes)

for i = 1:size(known_axes, 1)-1
    dot_prods = known_axes(i, :) * known_axes((i+1):end, :)';
    if length(find(abs(dot_prods)>eps(1))) > 0
        error('Initial axes are not orthogonal.', 'Initial axes are not orthogonal.');
    end
end

num_known_axes = size(known_axes, 1);
K = zeros(size(known_axes, 2));
K(1:num_known_axes, :) = known_axes;

% normalise known axes
K(1:num_known_axes, :) = K(1:num_known_axes, :) ./ repmat(sqrt(sum(K(1:num_known_axes, :).^2, 2)), 1, size(K, 2));
for i = (num_known_axes+1):size(K, 1)
    % perform svd to find a normal axes
    A = K(1:(i-1), :);
    [U D V] = svd(A);
    K(i, :) = V(:, end);
end

max_res = max(max(abs((K*K')-eye(size(K)))));
if max_res > eps(100)
    max_res
    error('Rotational matrix not orthgonal.', 'Rotational matrix not orthgonal.');
end

detK = det(K);
if ~(det(K) > 0)
%     warning('Rotational matrix not proper, negating last axis/row.', 'Rotational matrix not proper, negating last axis/row.');
    K(end, :) = -K(end, :);
    detK = det(K);
    if ~(det(K) > 0)
        detK
        error('Rotational matrix is still not proper.', 'Rotational matrix is still not proper.');
    end
end
